package com.mmall.admin;

import com.mmall.common.base.ServerResponse;
import com.mmall.common.util.ErrorUtil;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Scanner;

/**
 * @author guigu
 */
@Slf4j
@SpringBootApplication
@ControllerAdvice
@EnableTransactionManagement
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"com.mmall.facade"})
@MapperScan(basePackages = "com.mmall.admin.mapper")
@ComponentScan(basePackages = {"com.mmall.*"})
@EnableConfigurationProperties
public class MmallAdminApplication {

    public static void main(String[] args) {
        SpringApplication.run(MmallAdminApplication.class, args);
    }

    /**
     * 全局异常处理
     *
     * @param ex Exception
     * @return R
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ServerResponse defaultExceptionHandler(Exception ex) {
        return ErrorUtil.handException(ex);
    }
}
